/*
 * @Author: soso
 * @Date: 2022-02-08 12:51:35
 * @LastEditTime: 2022-03-10 11:02:16
 * @LastEditors: Please set LastEditors
 * @Description: 路径处理
 * @FilePath: /go-mesh-sync/core/cfiles/path.go
 */
package cfiles

import (
	"gomeshsync/config"
	"path/filepath"
)

//实际的服务器路径
func toRealSvrPath(relFilePath ...string) string {
	return filepath.Clean(filepath.Join(config.DirFiles, filepath.Join(relFilePath...)))
}

//服务器相对路径
func toRelSvrPath(realFilePath string) string {
	bPath := config.DirFiles
	rPath := realFilePath

	if !filepath.IsAbs(config.DirFiles) {
		bPath, _ = filepath.Abs(config.DirFiles)
	}

	if !filepath.IsAbs(realFilePath) {
		rPath, _ = filepath.Abs(realFilePath)
	}

	path, _ := filepath.Rel(bPath, rPath)
	return path
}

//实际的服务器文件掩码路径
func toFileMaskFilePath(relFilePath string) string {
	return getFileMaskFilePath(toRealSvrPath(relFilePath))
}

func getFileMaskFilePath(realFilePath string) string {
	return filepath.Join(filepath.Dir(realFilePath), "."+filepath.Base(realFilePath)+".ctfm")
}

// 上传文件临时命令
func getUploadCmdPath(orgiPath string) string {
	return orgiPath + ".cmd"
}
